"""
公告公示数据模式
"""
from datetime import datetime
from typing import Optional, List
from pydantic import BaseModel, Field

class AnnouncementBase(BaseModel):
    """公告基础模式"""
    title: str = Field(..., max_length=200, description="公告标题")
    excerpt: Optional[str] = Field(None, description="公告摘要")
    content: str = Field(..., description="公告内容")
    cover_image: Optional[str] = Field(None, max_length=500, description="封面图片URL")
    category: str = Field(..., max_length=50, description="公告分类")
    author: Optional[str] = Field("管理员", max_length=100, description="发布者")

class AnnouncementCreate(AnnouncementBase):
    """创建公告模式"""
    is_published: bool = Field(False, description="是否发布")

class AnnouncementUpdate(BaseModel):
    """更新公告模式"""
    title: Optional[str] = Field(None, max_length=200, description="公告标题")
    excerpt: Optional[str] = Field(None, description="公告摘要")
    content: Optional[str] = Field(None, description="公告内容")
    cover_image: Optional[str] = Field(None, max_length=500, description="封面图片URL")
    category: Optional[str] = Field(None, max_length=50, description="公告分类")
    author: Optional[str] = Field(None, max_length=100, description="发布者")
    is_published: Optional[bool] = Field(None, description="是否发布")

class AnnouncementStatusUpdate(BaseModel):
    """公告状态更新模式"""
    is_published: bool = Field(..., description="发布状态")

class AnnouncementResponse(AnnouncementBase):
    """公告响应模式"""
    id: int
    is_published: bool
    view_count: int
    published_at: Optional[datetime]
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class AnnouncementListResponse(BaseModel):
    """公告列表响应模式"""
    items: List[AnnouncementResponse]
    total: int
    page: int
    size: int
    pages: int

class AnnouncementStatsResponse(BaseModel):
    """公告统计响应模式"""
    total_announcements: int
    published_announcements: int
    draft_announcements: int
    total_views: int
